import {getComponentName} from '../../core/component-utils.js'
// 导入组件
const files = require.context("./", false, /\.vue$/);
// 处理组件
export const importComponents = (files) => {
    const path = require("path");
    const modules = {};
    files.keys().forEach((key) => {
        let name = path.basename(key, '.vue');
        if(name === 'index'){ // 如果是index.vue就用路径名标注
            name = path.dirname(key, '.vue');
        }
        modules[name] = files(key).default || files(key);
    });
    return modules;
};
const modules = importComponents(files);
export const install = (Vue) => {
    Object.keys(modules).map((component) => {
        const componentName = modules[component].name;
        if(componentName){
            Vue.component(componentName, modules[component]);
            const newComponentName = getComponentName(componentName);
            Vue.component(newComponentName, modules[component]);
        }
    });
};

// 判断是否是直接引入文件
if (typeof window !== "undefined" && window.Vue) {
    install(window.Vue);
}
export default { install };
